<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>智能养殖远程管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!-- <link rel="shortcut icon" href="../logo.png" /> -->
    <script type="text/javascript" src="../dashboard/js/jquery.js?v=${.Config.basic.version}"></script>
    <link rel="stylesheet" href="../plugins/layui/css/layui.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/layui/css/style.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_2575369_ywz1djtgesp.css" media="all">
    <link rel="stylesheet" href="../plugins/toastr/toastr.min.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="../dashboard/css/comon0.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_3564966_a6tt4yhnzge.css" media="all">
    <style>
        .pulll_left {
            float: left;
            position: absolute;
        }

        .huankong_node {
            background-color: #1b2c62;
            border: 1px solid rgba(67, 87, 134, 0.5);
            box-shadow: inset 0 0 10px rgba(49, 60, 119, 0.66);
            margin: 0.02rem;
            padding: 0.02rem;
            text-align: center;
            height: 1rem;
            border-radius: 0.05rem;
            cursor: pointer;
        }
        .huankong_node > .node_icon{
            color: #fff;
            /*display: inline;*/
            margin-top: 0.05rem;
            line-height: 0.35rem;
            font-size: 0.28rem;
            vertical-align: center;
        }
        .huankong_node > .node_value {
            /*color: #3acdfb;*/
            /*display: inline;*/
            line-height: 0.24rem;
            font-size: 0.2rem;
        }
        .huankong_node > .node_text {
            color: #8498b7;
            /*display: inline;*/
            line-height: 0.24rem;
            font-size: 0.12rem;
        }
        .iconfont {
            font-size: 0.3rem;
        }

        .layui-input, .layui-select, .layui-textarea {
            height: 0.31rem;
            line-height: 0.32rem;
            border-width: 1px;
            border-style: solid;
            background-color: transparent;!important;
            color: #8f97b3;
            border-radius: 5px;
            border: 0px solid #6c7492;
            border-top-color: rgb(108, 116, 146);
            border-right-color: rgb(108, 116, 146);
            border-bottom-color: rgb(108, 116, 146);
            border-left-color: rgb(108, 116, 146);
            text-align: right;
            text-align: center;
            font-size: 0.14rem;
        }

        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }

        .layui-nav {
            position: relative;
            padding: 0 0.1rem;
            background-color: transparent;
            color: #fff;
            border-radius: 2px;
            font-size: 0;
            box-sizing: border-box;
        }
        .layui-nav .layui-nav-item {
            position: relative;
            display: inline-block;
            *display: inline;
            *zoom: 1;
            vertical-align: middle;
            line-height: 0.5rem;
        }
        .layui-nav .layui-nav-item a {
            display: block;
            padding: 0 0.1rem;
            color: #fff;
            color: rgba(255,255,255,.7);
            transition: all .3s;
            -webkit-transition: all .3s;
        }
        .layui-nav-img {
            width: 0.25rem;
            height: 0.25rem;
            margin-right: 10px;
            border-radius: 50%;
        }
        .layui-nav-child {
            box-shadow: 0 2px 4px rgba(0,0,0,.12);
            border: 1px solid #061231;
            background-color: #fff;
            text-align: center;
        }
        a cite {
            font-style: normal;
            *cursor: pointer;
            margin-right: 10px;
        }
        [v-cloak]{
            display: none;
        }

        .full-height-under-title{
            height: calc(100% - 30px) !important;
        }

        

    </style>
</head>
<body>
<div class="loading">
    <div class="loadbox"> <img src="../dashboard/images/loading.gif"> ... </div>
</div>
<div class="head">
    <div class="menu menu2 pulll_left">
        <ul>
            <li><a href="../Home/Index" target="_self"><i class="layui-icon layui-icon-home layui-text-white"></i></a></li>
            <li><a href="#">

                    <form class="layui-form" lay-filter="form_select" >
                        <select  name="farm" lay-filter="farm" lay-verify="required" lay-search="" style="width: 100%;" >
                            <option value=""></option>
                        </select>
                    </form>
                </a>
            </li>
        </ul>
    </div>

    <h1>智能养殖远程管理系统</h1>



    <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">

        
        <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="fullscreen">
                <i class="layui-icon layui-icon-screen-full"></i>
            </a>
        </li>
        <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;">
                <img src="../img/user_white.png" class="layui-nav-img">
                <cite id="username" class=""></cite>
            </a>
            <dl class="layui-nav-child">
                <dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd>
            </dl>
        </li>

        <!--<li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="about"><i class="layui-icon layui-icon-more-vertical"></i></a>
        </li>
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-unselect>
            <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>
        </li>-->
    </ul>

    <!--<div class="time" id="showTime"></div>-->
    <script>
        var t = null;
        t = setTimeout(time, 1000);//開始运行
        function time() {
            clearTimeout(t);//清除定时器
            dt = new Date();
            var y = dt.getFullYear();
            var mt = dt.getMonth() + 1;
            var day = dt.getDate();
            var h = dt.getHours();//获取时
            var m = dt.getMinutes();//获取分
            var s = dt.getSeconds();//获取秒
            var t = null;
            document.getElementById("showTime").innerHTML = y + "年" + Appendzero(mt) + "月" + Appendzero(day) + "日" + Appendzero(h) + ":" + Appendzero(m);
            function Appendzero(obj) {
                if (obj < 10) return "0" + "" + obj;
                else return obj;
            }
            t = setTimeout(time, 1000); //设定定时器，循环运行
        }

    </script>

</div>

<div class="mainbox">
    <ul class="clearfix">
        <li>
            <div class="boxall" style="height: calc(50% - .15rem)">
                <div class="alltitle">日采食统计
                    <div class="pulll_right sebtn">
                        <a href="#" class="active" data-type="total">总量</a>
                        <a href="#" data-type="avg">头均</a>
                    </div>
                </div>

                <div class="boxnav" id="chart_feed">

                </div>
                <div class="boxfoot"></div>
            </div>
            <div class="boxall" style="height: calc(50% - .15rem)">
                <div class="alltitle">猪群统计</div>
                <div class="boxnav" >
                    <ul class="btbox">
                        <li id="chart_mode" style="width: 60% !important;"></li>
                        <!--<li id="chart_mode_1" style="width: 50% !important;"></li>-->
                        <li id="" style="width: 40% !important;" class="scrollDiv" style=" height:1.8rem">
                            <div class="sycm sycm2">
                                <ul class="clearfix" id="feed_display" >
                                    <!--<li style="width: 50% !important;">
                                        <h2 class="layui-text-white">{{todayFeed}}</h2>
                                        <span>今日下料(kg)</span>
                                    </li>
                                    <li style="width: 50% !important;">
                                        <h2 class="layui-text-white">{{todayWater}}</h2>
                                        <span>今日下水(L)</span>
                                    </li>
                                    <li style="width: 50% !important;">
                                        <h2 class="layui-text-white">{{monthFeed}}</h2>
                                        <span>本月下料(kg)</span>
                                    </li>
                                    <li style="width: 50% !important;">
                                        <h2 class="layui-text-white">{{monthWater}}</h2>
                                        <span>本月下水(L)</span>
                                    </li>-->

                                </ul>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="boxfoot"></div>
            </div>

        </li>
        <li>
            <div style="position: relative">
                <div class="barnav" id="vm-device" v-cloak>

                    <div class="bar">
                        <div class="barbox">
                            <ul class="clearfix">
                                <li class="pulll_left counter layui-text-blue" >{{deviceNum}}</li>
                                <li class="pulll_left counter layui-text-blue">{{onlineNum}}</li>
                                <li class="pulll_left counter layui-text-orange">{{offlineNum}}</li>
                                <li class="pulll_left counter layui-text-orange">{{disableNum}}</li>
                                <li class="pulll_left counter layui-text-red">{{alarmNum}}</li>
                            </ul>
                        </div>
                        <div class="barbox2">
                            <ul class="clearfix">
                                <li class="pulll_left">设备总数</li>
                                <li class="pulll_left">在线总数</li>
                                <li class="pulll_left">离线总数</li>
                                <li class="pulll_left">空栏</li>
                                <li class="pulll_left">告警设备</li>
                            </ul>
                        </div>

                    </div>
                </div>
            </div>
            <div class="mapbox">
                <div class="map">
                    <div class="map1"><img src="../dashboard/images/lbx.png"></div>
                    <div class="map2"><img src="../dashboard/images/jt.png"></div>
                    <div class="map3"><img src="../dashboard/images/map.png"></div>
                    <div class="map4" id="chart_map"></div>
                </div>
            </div>
        </li>
        <li>

            <div class="boxall" style="height: calc(100% - .15rem)">
                <div class="alltitle">环控信息
                    <div class="pulll_right">
                        <!--<a href="#"><span></span>已维修</a>
                        <a href="#"><span></span>未维修</a>-->
                    </div>
                </div>
                <div class="boxnav" id="vm-house">
                    <form class="layui-form" lay-filter="form_select" >
                        <select  name="house" lay-filter="house" lay-verify="required" lay-search="" style="width: 100%;" >
                            <option value=""></option>
                        </select>
                    </form>
                    <div class="layui-carousel" id="carousel1" lay-filter="carousel1">

                        <div carousel-item="">
                            <template  v-for="(item,index) in houses">
                            <div>
                                <div class="layui-row ">
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-wendu"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">温度(℃)</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-shidu"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">湿度(%)</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-anqi"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">氨气(ppm)</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-eryanghuatan"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">二氧化碳(ppm)</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-yali"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">负压(Pa)</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-dengguang"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">光照</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-jiare"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">加热</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-zhileng"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">制冷</div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-penwuxitong"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">喷雾</div>
                                        </div>
                                    </div>

                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-fengji2"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">风机</div>
                                        </div>
                                    </div>

                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-juanlian1"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">巻帘</div>
                                        </div>
                                    </div>

                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-chuanglian"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">滑帘</div>
                                        </div>
                                    </div>

                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-juanlian"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">侧风窗</div>
                                        </div>
                                    </div>

                                    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-lg3">
                                        <div class="huankong_node">
                                            <div class="node_icon">
                                                <i class="iconfont icon-tianchuang"></i>
                                            </div>
                                            <div class="node_value layui-text-mute">-</div>
                                            <div class="node_text">天花窗</div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            </template>
                        </div>

                    </div>
                </div>
                <div class="boxfoot"></div>
            </div>

        </li>
    </ul>
    <!-- <div class="copyright">版权所有：东莞浩正科技有限公司</div> -->
</div>

<div class="mainbox2">
    <ul class="clearfix">
        <li>

            <div class="boxall" style="height: 100%">
                <div class="alltitle">料塔料线
                    <!--<div class="pulll_right sebtn">
                        <a href="#" class="active">近一周</a>
                        <a href="#">近一月</a>
                        <a href="#">近三月</a>
                    </div>-->
                    <div class="pulll_right">
                        <i class="layui-icon layui-icon-left layui-text-mute"></i>
                        <i class="layui-text-mute">当前无设备</i>
                        <i class="layui-icon layui-icon-right layui-text-mute"></i>
                    </div>
                </div>
                <div class="boxnav" >
                    <ul class="btbox" >
                        <li id="chart_liaota" style="width: 60%;"></li>
                        <li id="" style="width: 40%;">
                            <div class="sycm sycm2">
                                <ul class="clearfix">
                                    <li style="width: 100%;">
                                        <h2 class="layui-text-mute">0.0/0.0</h2>
                                        <span>剩余料量/总量(吨)</span>
                                    </li>
                                    <li style="width: 100%;">
                                        <h2 class="layui-text-mute">00:00</h2>
                                        <span>下次送料时间</span>
                                    </li>
                                    <li style="width: 100%;">
                                        <h2 class="layui-text-mute">00:00</h2>
                                        <span>下次下料时间</span>
                                    </li>

                                </ul>
                            </div>
                        </li>
                    </ul>
                </div>


                <!--<ul class="tabnav">
                    <li style=" height: auto;">
                        <div class="gdhead">
                            <span>料塔</span><span>饲料 </span><span>下次下料</span><span>下次下料</span> <span>余料 </span>
                        </div>
                        <div class="scrollDiv" style=" height:2.1rem">

                            <ul class="smjl">
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                                <li><span>料塔1</span><span>香芋</span><span>12:00</span><span>13:00</span><span>69.3kg</span>
                                </li>
                            </ul>
                        </div>
                    </li>
                </ul>-->
                <div class="boxfoot"></div>
            </div>

        </li>
        <li>
            <div class="boxall" style="height:100%">
                <div class="alltitle">设备统计分析

                </div>
                <div class="boxnav">
                    <ul class="btbox">
                        <li id="chart_online" style="width: 50%;"></li>
                        <li id="chart_province_sort" style="width: 50%;"></li>
                    </ul>
                </div>
                <div class="boxfoot"></div>
            </div>
        </li>

        <li>
            <div class="boxall" style="height: 100%;">
                <div class="alltitle">告警统计
                    <div class="pulll_right sebtn">
                        <a href="#" class="active" data-type="list" data-type="alarm_detail">详情</a>
                        <a href="#" data-type="chart" data-type="alarm_chart">统计</a>
                    </div>
                </div>
                <div class="boxnav" id="">
                    
                    <div id="alarm_list" style="height: 100%;">
                        <div class="gdhead">
                            <span>场</span><span>栏舍</span><span>告警信息 </span><span>发生时间</span>
                        </div>
                        <div class="scrollDiv1 full-height-under-title">

                            <ul class="smjl">
                                <!-- <li><span class="">aaa</span><span class="">测试</span><span>堵料告警</span><span>2022-09-09 22:21:21</span></li>
                                <li><span class="">aaa</span><span class="">测试</span><span>堵料告警</span><span>2022-09-09 22:21:21</span></li> -->
                                
                            </ul>
                        </div>
                    </div>
                    <div id="chart_alarm" style="height: 100%;display: none;"></div>
                </div>
                <div class="boxfoot"></div>
            </div>
        </li>
    </ul>
</div>
<script src="../js/check_screen.js?v=${.Config.basic.version}"></script>

</body>
<script src="../plugins/layui/layui.js?v=${.Config.basic.version}"></script>
<script src="../plugins/vue/vue.min.js?v=${.Config.basic.version}"></script>
<!-- <script  src="/dashboard/js/echarts.min.js"></script> -->
<script src="../plugins/echart/echarts-4.8.min.js?v=${.Config.basic.version}"></script>
<script  src="../dashboard/js/echarts-liquidfill.js"></script>
<script src="../dashboard/js/china.js?v=${.Config.basic.version}"></script>
<script  src="../dashboard/js/charts.js?v=${.Config.basic.version}"></script>
<script src="../dashboard/js/jquery.liMarquee.js?v=${.Config.basic.version}"></script>
<script src="../plugins/jquery.slimscroll.min.js?v=${.Config.basic.version}"></script>
<script src="../plugins/moment.min.js?v=${.Config.basic.version}"></script>
<script src="../plugins/toastr/toastr.min.js?v=${.Config.basic.version}"></script>
<script src="../js/utils.js?v=${.Config.basic.version}"></script>
<script src="../js/func.js?v=${.Config.basic.version}"></script>
<script src="../js/watermark.js?v=${.Config.basic.version}"></script>
<script>
    var form=null;
    var element=null;
    var carousel=null;
    var farms=null;
    var houses=null;
    var curfarm_ = null;
    var cur_farm_id =null;
    var cur_house = null;
    var token=null;
    var feed_avg =false;
    var alarm_show_chart = false;
    var modeData = [];
    var user_info = null;
    var rate = 1;

    var vm_house = new Vue({
        el: '#vm-house',
        data: {
            houses:[],
            selectHouseItem:null,
        },
        methods: {
        },
        watch:{
            houses:function () {
                this.$nextTick(function () {
                    console.info("houses render done!")
                    //图片轮播
                    carousel.render({
                        elem: '#carousel1'
                        ,width: '100%'
                        ,height: '100%'
                        ,interval: 5000
                        ,autoplay:false
                        ,arrow:'always'
                        ,indicator:'none'
                    });
                })
            }
        }
    });

    /*var vm_feed = new Vue({
        el: '#vm-feed',
        data :{
            todayFeed:'0',
            todayWater:'0',
            monthFeed:'0',
            monthWater:'0',
            pigNum:'0',
        },
        methods: {
        },
        watch:{
            pigNum :function(val, oval) {
                console.info('pigNum',val,oval);
                this.pigNum = val
            },

        }
    });*/

    var vm_device = new Vue({
        el: '#vm-device',
        data: {
            onlineNum:'0',
            offlineNum:'0',
            offlineNum:'0',
            deviceNum:'0',
            alarmNum:'0',
            disableNum:'0',
            pigNum:'0',
        },
        methods: {
        }
    });

    layui.config({
        base: '../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','form','element','carousel'], function(){
        token = window.localStorage.getItem("token");
        if(!token){
            setTimeout(function(){
                window.location.href = '../Login/';
            },50);
        }
        token = 'Bearer ' + token;

        form = layui.form;
        element = layui.element;
        carousel = layui.carousel;

        $.ajax({
            type: 'GET',
            url: '../Api/User',
            data: {},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (data) {
                //console.info(data)
                user_info = data;
                window.localStorage.setItem("user_info",JSON.stringify(data))
                if(data.name){
                    $("#username").html(data.name);
                    setWaterMark(data.name, data.phone)
                }
                if(user_info.userid=='13680271056'){
                    rate = 22;
                }

                $.ajax({
                    type: 'GET',
                    url: '../Api/Farm/SummaryList',
                    data: {},
                    beforeSend: function (request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    dataType: "json",
                    success: function (res) {
                        if(res.code>=0){
                            //console.info(res.data);
                            farms = res.data;
                            if(farms.length>0){
                                /*if(cur_farm_id){
                                    for(var i=0;i<farms.length;i++){
                                        if(farms[i].id==cur_farm_id){
                                            cur_farm = farms[i];
                                        }
                                    }
                                }else{
                                    cur_farm_id = farms[0].id;
                                    cur_farm = farms[0];
                                }*/

                                renderFarmSelect();
                                loadHouse(cur_farm_id,null);
                                loadAll(cur_farm_id);
                                setInterval(function () {
                                    loadAll(cur_farm_id);
                                },60*1000*10);

                                var deviceNum = 0;
                                var onlineNum = 0;
                                var offlineNum = 0;
                                var disableNum = 0;
                                var alarmNum = 0;
                                for(var i=0;i<farms.length;i++){
                                    if(farms[i].summary_info)
                                    {
                                        console.info(farms[i].summary_info);
                                        deviceNum += farms[i].summary_info.device_num;
                                        onlineNum += farms[i].summary_info.online_num;
                                        offlineNum += farms[i].summary_info.offline_num;
                                        disableNum += farms[i].summary_info.num_stop;
                                        alarmNum += farms[i].summary_info.alarm_device_num;
                                    }
                                }

                                vm_device.deviceNum = deviceNum;
                                vm_device.onlineNum = onlineNum;
                                vm_device.offlineNum = offlineNum;
                                vm_device.disableNum = disableNum;
                                vm_device.alarmNum = alarmNum;
                            }

                        }else{
                            layer.alert(res.msg);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg('加载信息失败');
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载用户信息失败');
            }
        });

        



        setfont();
        initCharts();



        $(".sebtn a").click(function () {
            $(this).addClass("active").siblings().removeClass("active");
            console.info($(this).context.dataset.type)
            var type = $(this).context.dataset.type;

            if(type=='total'){
                feed_avg = false;
                loadDaySumFeed(cur_farm_id);
            }else if(type=='avg'){
                feed_avg = true;
                loadDayAvgFeed(cur_farm_id);
            }

            if(type=='chart'){
                alarm_show_chart = true;
                $("#chart_alarm").show();
                $("#alarm_list").hide();
                loadFeedNodeData(cur_farm_id);
            }else if(type=='list'){
                alarm_show_chart = false;
                $("#chart_alarm").hide();
                $("#alarm_list").show();
                loadFeedNodeData(cur_farm_id);
            }
        });

        //切换
        form.on('select(farm)', function(data){
            var id=data.value;
            console.info("farmid",id);
            cur_farm_id = id;
            loadHouse(cur_farm_id,null);
            loadAll(cur_farm_id);
        });

        form.on('select(house)', function(data){
            var id=data.value;
            console.info("houseid",id);
        });

        $(".loading").fadeOut()

        /*$('.scrollDiv').liMarquee('destroy');
        $('.scrollDiv').liMarquee({
            direction: 'up',//身上滚动
            runshort: false,//内容不足时不滚动
            scrollamount: 20,//速度
            circular:true
        });*/


    });

    $(window).resize(function(){
        setfont();
    });

    function setfont(){
        var whei=$(window).width()
        $("html").css({fontSize:whei/20})

    }

    function loadHouse(farmid,houseid) {
        $.ajax({
            type: 'GET',
            url: '../Api/House',
            data: {farmid:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    houses = res.data;
                    vm_house.houses = houses;

                    if(res.count>0){
                        if(houseid){
                            var matchs= $.grep(res.data,function (item) {
                                return item.id ==houseid;
                            })
                            if(matchs.length>0){
                                cur_house = matchs[0];
                            }else{
                                cur_house  = res.data[0];
                            }
                        }else{
                            cur_house  = res.data[0];
                        }
                    }
                    renderHouseSelect();
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }
    function renderFarmSelect(){
        //栏舍下拉
        var html="<option selected value=''>全局</option>";
        for(var i=0;i<farms.length;i++){
            var selectd="";
            if(farms[i].id==cur_farm_id){
                selectd=" selected ";
            }
            html+="<option "+selectd+" value=\""+farms[i].id+"\">"+farms[i].farmname+"</option>";
        }

        $("select[name='farm']").html(html);

        form.render('select');
    }
    function renderHouseSelect(){

        //栏舍下拉
        var html="";
        for(var i=0;i<houses.length;i++){
            var selectd="";
            if(houses[i].id==cur_house.id){
                selectd=" selected ";
            }
            html+="<option "+selectd+" value=\""+houses[i].id+"\">"+houses[i].housename+"</option>";
        }

        $("select[name='house']").html(html);
        form.render('select');
    }

    function loadAll(farmid) {
        console.info("farmid:",farmid);

        if(feed_avg){
            loadDayAvgFeed(farmid);
        }else{
            loadDaySumFeed(farmid)
        }
        loadSumMode(farmid);
        //loadTodayFeed(farmid);
        //loadMonthFeed(farmid);
        //loadDeviceData(farmid);
        loadBftData(farmid);
        loadProvinceSort(farmid);
        loadMapData(farmid);
        loadFeedNodeData(farmid);
        if(farmid)
        {
            loadFarmSummaryInfo(farmid);
        }
        
    }


    function loadDaySumFeed(farmid) {
        //layer.load(1);
        var begin = moment().add(-10, 'days').format('YYYY-MM-DD');
        var end = moment().add(0, 'months').format('YYYY-MM-DD HH:mm');
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/DaySumFeed',
            data: {id:farmid,begin:begin,end:end},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    var day_arr =[];
                    var val_arr =[];
                    var val1_arr =[];

                    

                    //console.info(res.data)
                    for(var i=0;i<res.data.length;i++){
                        var his = res.data[i];
                        var feed = parseFloat(his.day_use_feed_auto)/1000+parseFloat(his.day_use_feed_man)/1000;
                        var water = parseFloat(his.day_use_water_auto)/1000+parseFloat(his.day_use_water_man)/1000;
                        val_arr.push((feed*rate).toFixed(2));
                        val1_arr.push((water*rate).toFixed(2));
                        day_arr.push(moment(his.his_date).format("MM/DD") );
                    }


                    option_feed_total.series[0].data= val_arr;
                    option_feed_total.series[1].data= val1_arr;
                    option_feed_total.xAxis[0].data = day_arr;

                    setTimeout(function(){
                        chart_feed.setOption(option_feed_total);
                    },200);

                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }
    function loadDayAvgFeed(farmid) {
        //layer.load(1);
        var begin = moment().add(-10, 'days').format('YYYY-MM-DD');
        var end = moment().add(0, 'months').format('YYYY-MM-DD HH:mm');
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/DaySumFeed',
            data: {id:farmid,begin:begin,end:end},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){

                    var day_arr =[];
                    var val_arr =[];
                    var val1_arr =[];

                    var last_pig_num = 0;
                    if(res.data.length>0){
                        last_pig_num = res.data[res.data.length-1].pig_num; 
                    }
                    for(var i=0;i<res.data.length;i++){
                        var his = res.data[i];
                        var pig_num = his["pig_num"];
                        if(pig_num && pig_num>0){
                            var feed = parseFloat(his.day_use_feed_auto)+parseFloat(his.day_use_feed_man);
                            var water = parseFloat(his.day_use_water_auto)+parseFloat(his.day_use_water_man);
                            val_arr.push((feed/pig_num).toFixed(2));
                            val1_arr.push((water/pig_num).toFixed(2));
                            day_arr.push(moment(his.his_date).format("MM/DD") );
                            last_pig_num = pig_num;
                            console.info("last_pig_num=",last_pig_num)
                        }else{
                            console.info("pig_num缺失，使用last_pig_num",last_pig_num)
                            var feed = parseFloat(his.day_use_feed_auto)+parseFloat(his.day_use_feed_man);
                            var water = parseFloat(his.day_use_water_auto)+parseFloat(his.day_use_water_man);
                            val_arr.push((feed/last_pig_num).toFixed(2));
                            val1_arr.push((water/last_pig_num).toFixed(2));
                            day_arr.push(moment(his.his_date).format("MM/DD") );
                        }
                    }


                    option_feed_avg.series[0].data= val_arr;
                    option_feed_avg.series[1].data= val1_arr;
                    option_feed_avg.xAxis[0].data = day_arr;

                    setTimeout(function(){
                        chart_feed.setOption(option_feed_avg);
                    },200);
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }
    //获取模式
    function loadSumModeBak(farmid) {
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/SumMode',
            data: {id:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    /*var color = [
                        "#00ffff",
                        "#00cfff",
                        "#006ced",
                        "#ffe000",
                        "#ffa800",
                        "#ff5b00",
                        "#ff3000",
                    ];*/
                    var color = [
                        "#FFB800", //停用
                        "#006ced", //妊娠
                        "#6f9aa4", //空怀
                        "#0f6d47", //保育
                        "#54e08c", //育肥
                        "#4c4da0", //哺乳
                        "#2a479d", //公猪
                    ];
                    var data = [];
                    //只显示 "公猪", "哺乳", "妊娠", "停用"
                    //"6", "5", "1", "0"
                    modeData = [];
                    var typeData =[];
                    if(res.data){
                        /*modeData = $.grep(res.data,function (item) {
                            return item.mode==6 || item.mode==5 || item.mode==1 ||item.mode==0;
                        });*/
                        modeData = res.data;
                    }

                    console.info(modeData)
                    for (var i = 0; i < modeData.length; i++) {
                        if(modeData[i].num==0){
                            modeData[i].num = null;
                            //continue;
                        }
                        var name = "";
                        if(modeData[i].device_type=="DMXFGW"){
                            name = decodeModeNew(modeData[i].mode)
                        }else{
                            name = decodeMode(modeData[i].mode)
                        }
                        data.push(
                            {
                                value: modeData[i].num*rate,
                                name: name,
                                itemStyle: {
                                    normal: {
                                        borderWidth: 2,
                                        shadowBlur: 10,
                                        borderColor: color[i],
                                        shadowColor: color[i],
                                    },
                                },
                            }
                        );
                    }

                    option_mode.color= color;
                    console.info(data)
                    option_mode.series[0].data= data;
                    option_mode.legend.data = typeData;

                    setTimeout(function(){
                        chart_mode.setOption(option_mode);
                    },100);
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }
    
    function loadSumMode(farmid) {
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/SumMode',
            data: {id:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    console.info(res.data);
                    var name_arr =[];
                    var data_arr =[];

                    var son_num=0;
                    var pig_1=0;
                    var pig_2=0;
                    var pig_3=0;
                    var pig_4=0;
                    var pig_5=0;

                    

                    name_arr.push("公猪");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#e3f7ff"}
                    });

                    name_arr.push("仔猪");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#CC6699"}
                    });

                    name_arr.push("妊娠");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#55e4c1"}
                    });

                    name_arr.push("哺乳");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#55e4c1"}
                    });

                    name_arr.push("保育");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#1E9FFF"}
                    });

                    name_arr.push("育肥");
                    data_arr.push({
                        value:0,
                        itemStyle: {color: "#1E9FFF"}
                    });

                    
                    for(var i=0;i<res.data.length;i++){
                        var item = res.data[i];
                        son_num+=item.son_num;
                        
                        if(item.device_type=="DMXFGW"){
                            if(item.mode==1){
                                //妊娠
                                pig_1+=item.num;
                            }
                            else if(item.mode==2){
                                //哺乳
                                pig_2+=item.num;
                            }
                            else if(item.mode==3){
                                //保育
                                pig_3+=item.num;
                            }
                            else if(item.mode==4){
                                //育肥
                                pig_4+=item.num;
                            }
                            else if(item.mode==5){
                                //公猪
                                pig_5+=item.num;
                            }
                            
                        }else{
                            if(item.mode==5){
                                //哺乳
                                pig_2+=item.num;
                            }
                            else if(item.mode==6){
                                //公猪
                                pig_5+=item.num;
                            }
                        }
                    }

                    data_arr[0].value = pig_5;//公猪
                    data_arr[1].value = son_num;//仔猪
                    data_arr[2].value = pig_1;//妊娠
                    data_arr[3].value = pig_2;//哺乳
                    data_arr[4].value = pig_3;//保育
                    data_arr[5].value = pig_4;//育肥
                    

                    option_mode_new.series[0].data= data_arr;
                    option_mode_new.xAxis[0].data = name_arr;

                    setTimeout(function(){
                        chart_mode.setOption(option_mode_new);
                    },200);
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }

    //停止使用

    /*function loadDeviceData(farmid) {
        //layer.load(1);
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/DeviceData',
            data: {id:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    vm_device.onlineNum =res.data.onlineNum;
                    vm_device.deviceNum =res.data.deviceNum;
                    vm_device.offlineNum = vm_device.deviceNum - vm_device.onlineNum;
                    vm_device.alarmNum =res.data.alarmNum + vm_device.offlineNum;
                    vm_feed.pigNum = res.data.pigNum;

                    var per = (vm_device.onlineNum/vm_device.deviceNum*100).toFixed(1);
                    option_online.series[0].data = [per,0,0];
                    option_online.yAxis[1].data = [per,0,0];
                    chart_online.setOption(option_online);

                    //per = (vm_device.alarmNum/vm_device.deviceNum*100).toFixed(1);
                    option5.radar[0].indicator = [
                        { text: '离线', max: vm_device.deviceNum },
                        { text: '堵料', max: vm_device.deviceNum },
                        { text: '空转', max: vm_device.deviceNum },
                        { text: '无水料', max: vm_device.deviceNum },
                        { text: '电机故障', max: vm_device.deviceNum },
                        { text: '温度高', max: vm_device.deviceNum },
                        { text: '温度低', max: vm_device.deviceNum },
                        { text: '其他', max: vm_device.deviceNum },
                    ];
                    option5.series[0].data[0].value = [vm_device.offlineNum, 0, 0, 0,0,0,0,0];
                    chart5.setOption(option5);



                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }*/
    function loadBftData(farmid) {
        setTimeout(function(){
            var color="#f4ea2a";
            //取消动态颜色
            /*
            if(per>=40){
                color="#133678";
            }else if(per<20){
                color="#d81e06";
            }else{
                color="#df8627";
            }*/

            option_liaota.color = color;
            option_liaota.series[0].data = [0];
            chart_liaota.setOption(option_liaota);
        }, 500);
    }
    function loadProvinceSort(farmid,begin,end) {

        $.ajax({
            type: 'GET',
            url: '../Api/Device/Feednode/ProvinceSort',
            data: {farmid:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    console.info(res.data);

                    var valueArr=[];
                    var nameArr=[];
                    if(res.data.length>0){
                        for(var i=0;i<res.data.length;i++){
                            valueArr.push(res.data[i].num*rate);
                            nameArr.push(res.data[i].province);
                            if(i>8){
                                break;
                            }
                        }
                    }
                    setTimeout(function(){
                        option_province_sort.yAxis[0].data = nameArr;
                        option_province_sort.series[0].data = valueArr;
                        chart_province_sort.setOption(option_province_sort);
                    }, 200);

                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }
    function loadMapData(farmid){

        $.ajax({
            type: 'GET',
            url: '../Api/Farm/MapData',
            data: {id:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    var farms = res.data;
                    console.info(farms);
                    //

                    var farmData = [];
                    var geoCoordMap={};
                    for(var i=0;i<farms.length;i++){
                        var farm = farms[i];
                        farmData.push({name: farm.farmname, value: farm.deviceNum*rate});
                        geoCoordMap[farm.farmname] = [farm.x,farm.y];
                    }

                    console.info(farmData)
                    console.info(geoCoordMap)

                    var mapData = [];
                    for (var i = 0; i < farmData.length; i++) {
                        console.info(farmData[i])
                        var geoCoord = geoCoordMap[farmData[i].name];

                        if (geoCoord) {
                            mapData.push({
                                //name: farmData[i].name,
                                name:farmData[i].name+"\r\n"+"设备:"+farmData[i].value+"个",
                                value: geoCoord.concat(farmData[i].value),
                                itemStyle: {
                                    normal: {
                                        //color: color
                                    }
                                }
                            });
                        }
                    }

                    console.info(mapData)

                    /*是否显示标签*/
                    if(!farmid||farmid.length==0){
                        map_option.series[0].label.normal.show=false;
                    }else{
                        map_option.series[0].label.normal.show=true;
                    }

                    map_option.series[0].data = mapData;
                    //map_option.series[1].data = mapData;
                    chart_map.setOption(map_option);
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });


    }

    //获取子设备数据
    function loadFeedNodeData(farmid){
        $.ajax({
            type: 'GET',
            url: '../Api/Device/Feednode/Simple',
            data: {farmid:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    console.info(res.data);

                    //统计基本
                    var onlineNum = 0;
                    var offlineNum = 0;
                    var deviceNum = 0;
                    var offlineNum = 0;
                    var alarmNum = 0;
                    var disableNum = 0;
                    var pigNum = 0;
                    var onlinePer = 0;
                    //离线,堵料,空转,无水料,电机故障,温度高,温度低,其他
                    var alarmNum1= 0,alarmNum2= 0,alarmNum3= 0,alarmNum4= 0,alarmNum5= 0,alarmNum6= 0,alarmNum7= 0,alarmNum8 = 0;
                    // var modePigNum = {
                    //     "停用":0,
                    //     "妊娠":0,
                    //     "空怀":0,
                    //     "保育":0,
                    //     "育肥":0,
                    //     "哺乳":0,
                    //     "公猪":0,
                    //     "仔猪":0, //哺乳时候显示带仔数
                    // };//模式下猪只个数统计

                    var son_num=0;
                    var pig_1=0;
                    var pig_2=0;
                    var pig_3=0;
                    var pig_4=0;
                    var pig_5=0;

                    if(res.data){
                        var items = res.data;
                        deviceNum = items.length;
                        for(var i=0;i<items.length;i++)
                        {
                            /*if(items[i].online){
                                onlineNum += 1;
                            }
                            if(items[i].alarm){
                                alarmNum+=1;
                            }*/

                            if(items[i].online==1){
                                onlineNum += 1;
                                if(items[i].alarm || items.alarm_ext){
                                    alarmNum+=1;
                                    //console.info(i+" 告警");
                                }
                            }else if(items[i].online==0){
                                //console.info(i+" 离线");
                                alarmNum+=1;
                            }else{
                                //从未在线过，不当作离线
                            }

                            //统计大猪个数
                            /*if(items[i].mode){
                                pigNum+=(1*rate);
                                modePigNum[decodeMode(items[i].mode)]+=(1*rate);
                                if(items[i].mode==5){
                                    //哺乳
                                    modePigNum["仔"]+=items[i].son;
                                }
                            }else{
                                disableNum+=rate; //统计停用
                            }*/

                            var item = res.data[i];
                            son_num+=item.son;
                            pigNum+=item.pig_num;
                            if(item.mode==0){
                                disableNum++;
                            }
                            if(item.device_type=="DMXFGW"){
                                if(item.mode==1){
                                    //妊娠
                                    pig_1+=item.pig_num;
                                }
                                else if(item.mode==2){
                                    //哺乳
                                    pig_2+=item.pig_num;
                                }
                                else if(item.mode==3){
                                    //保育
                                    pig_3+=item.pig_num;
                                }
                                else if(item.mode==4){
                                    //育肥
                                    pig_4+=item.pig_num;
                                }
                                else if(item.mode==5){
                                    //公猪
                                    pig_5+=item.pig_num;
                                }
                                
                            }else{
                                if(item.mode==5){
                                    //哺乳
                                    pig_2+=item.pig_num;
                                }
                                else if(item.mode==6){
                                    //公猪
                                    pig_5+=item.pig_num;
                                }
                            }

                            //统计告警
                            if(items[i].alarm){
                                if(items[i].alarm==1){
                                    alarmNum2+=1;
                                }else if(items[i].alarm==2){
                                    alarmNum2+=1;
                                }else if(items[i].alarm==3){
                                    alarmNum8+=1;
                                }
                            }

                            //统计堵料告警
                            if(items[i].alarm_ext>0){
                                alarmNum+=1;
                                alarmNum3 += 1;
                            }
                        }
                    }
                    //console.info("modePigNum",modePigNum);
                    offlineNum = deviceNum - onlineNum;
                    alarmNum1 = offlineNum;
                    onlinePer = (onlineNum/deviceNum*100).toFixed(1);

                    //vm_device.onlineNum =onlineNum*rate;
                    //vm_device.deviceNum =deviceNum*rate;
                    //vm_device.offlineNum = offlineNum*rate;
                    //vm_device.disableNum = disableNum*rate;
                    //vm_device.alarmNum =alarmNum;

                    option_online.series[0].data = [onlinePer,0,0];
                    option_online.yAxis[1].data = [onlinePer,0,0];
                    chart_online.setOption(option_online);

                    //告警分析
                    option_alarm.radar[0].indicator = [
                        { text: '离线', max: vm_device.alarmNum },
                        { text: '堵料', max: vm_device.alarmNum },
                        { text: '空转', max: vm_device.alarmNum },
                        { text: '无水料', max: vm_device.alarmNum },
                        { text: '电机故障', max: vm_device.alarmNum },
                        { text: '温度高', max: vm_device.alarmNum },
                        { text: '温度低', max: vm_device.alarmNum },
                        { text: '其他', max: vm_device.alarmNum },
                    ];


                    option_alarm.series[0].data[0].value = [alarmNum1,alarmNum2,alarmNum3,alarmNum4,alarmNum5,alarmNum6,alarmNum7,alarmNum8];

                    if(alarm_show_chart){
                        //显示图表
                        console.info('show alarm chart');
                        
                        if(!chart_alarm){
                            chart_alarm = echarts.init(document.getElementById('chart_alarm'));
                        }

                        chart_alarm.setOption(option_alarm);
                    }else{
                        //显示滚动告警
                        
                        console.info('show alarm list');
                        loadFarmAlarm(farmid);
                    }


                    //展示汇总数据
                    $.ajax({
                        type: 'GET',
                        url: '../Api/Farm/SumFeed',
                        data: {id:farmid},
                        beforeSend: function(request) {
                            request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                        },
                        dataType: "json",
                        success: function (res) {
                            if(res.code>=0){
                                var month_data = res.data.month;
                                var day_data = res.data.day;
                                var month_feed = parseFloat(month_data.month_use_feed_auto)+parseFloat(month_data.month_use_feed_man);
                                var month_water = parseFloat(month_data.month_use_water_auto)+parseFloat(month_data.month_use_water_man);

                                var day_feed = parseFloat(day_data.day_use_feed_auto)+parseFloat(day_data.day_use_feed_man);
                                var day_water = parseFloat(day_data.day_use_water_auto)+parseFloat(day_data.day_use_water_man);

                                //console.info(month_feed,month_water,day_feed,day_water)
                                var todayFeed =(day_feed/1000).toFixed(2);
                                var todayWater =(day_water/1000).toFixed(2);
                                var monthFeed =(month_feed/1000).toFixed(2);
                                var monthWater =(month_water/1000).toFixed(2);
                                $("#feed_display").empty();
                                var html = "";
                                //html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+todayFeed+"</h2><span>今日下料(吨)</span></li>";
                                //html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+todayWater+"</h2><span>今日下水(吨)</span></li>";
                                //html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+monthFeed+"</h2><span>本月下料(吨)</span></li>";
                                //html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+monthWater+"</h2><span>本月下水(吨)</span></li>";

                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pigNum+"</h2><span>猪只总数</span></li>";

                                /*for (let key in modePigNum) {
                                    console.log(key, modePigNum[key])
                                    if(modePigNum[key]>0){
                                        if(key=='公猪'){
                                            html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+modePigNum[key]+"</h2><span>"+key+"</span></li>";
                                        }else{
                                            html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+modePigNum[key]+"</h2><span>"+key+"猪</span></li>";
                                        }

                                    }
                                }*/

                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pig_1+"</h2><span>妊娠猪</span></li>";
                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pig_2+"</h2><span>哺乳猪</span></li>";
                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pig_3+"</h2><span>保育猪</span></li>";
                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pig_4+"</h2><span>育肥猪</span></li>";
                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+son_num+"</h2><span>仔猪</span></li>";
                                html+="<li style=\"width: 50% !important;\"><h2 class=\"layui-text-white\">"+pig_5+"</h2><span>公猪</span></li>";

                                $("#feed_display").html(html);
                                $('.scrollDiv').liMarquee('destroy');
                                $('.scrollDiv').liMarquee({
                                    direction: 'up',//身上滚动
                                    runshort: false,//内容不足时不滚动
                                    scrollamount: 20,//速度
                                    circular:true
                                });
                            }else{
                                layer.alert(res.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.msg('加载信息失败');
                        },
                        complete: function(XMLHttpRequest, textStatus) {
                            layer.closeAll('loading');
                        },
                    });

                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }

    function loadFarmSummaryInfo(farmid){
        $.ajax({
            type: 'GET',
            url: '../Api/Farm/SummaryInfo',
            data: {id:farmid},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    var obj=res.data;
                    console.info(obj);
                    vm_device.deviceNum = obj.device_num;
                    vm_device.onlineNum = obj.online_num;
                    vm_device.offlineNum = obj.offline_num;
                    vm_device.disableNum = obj.num_stop;
                    vm_device.alarmNum = obj.alarm_device_num;
                    }else{
                        toastr.warning(res.msg, "异常");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('加载信息失败');
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },

            });
    }

    function loadFarmAlarm(farmid){
        $.ajax({
            type: 'GET',
            url: '../Api/Alarm',
            data: {farmid:farmid,status:1},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    //console.info(res.data);
                    cur_alarm_data = res.data;
                    //<li><span class="">测试</span><span>堵料告警</span><span>2022-09-09 22:21:21</span></li>
                    
                    $(".smjl").empty();
                    var html = "";
                    if(res.data.length>0){
                        for(var i=0;i<res.data.length;i++){
                            var item = res.data[i];
                            if(item.device_type=="HZFGW_NODE"||item.device_type=="NMSWQGW_NODE"){
                                html+="<li><span class=''>"+item.farmname+"</span><span>"+item.housename+"</span><span>栏位"+item.remark+" "+item.alarm_content+"</span><span>"+item.add_time+"</span></li>";
                            }else if(item.device_type=="HZFGW"|| item.device_type=="DMXFGW"){
                                html+="<li><span class=''>"+item.farmname+"</span><span>"+item.housename+"</span><span>"+item.alarm_content+"</span><span>"+item.add_time+"</span></li>";
                            }

                            if(i>1000){
                                break
                            }
                            
                        }
                    }
                    $(".smjl").html(html);

                    $('.scrollDiv1').liMarquee('destroy');
                    $('.scrollDiv1').liMarquee({
                        direction: 'up',//身上滚动
                        runshort: false,/*内容不足时不滚动*/
                        scrollamount: 20,//速度
                        circular:true
                    });

                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }

    function initCharts(){
        chart_map = echarts.init(document.getElementById('chart_map'));

        chart_feed = echarts.init(document.getElementById('chart_feed'));
        chart_mode = echarts.init(document.getElementById('chart_mode'));
        chart_liaota = echarts.init(document.getElementById('chart_liaota'));
        chart_online = echarts.init(document.getElementById('chart_online'));
        chart_province_sort = echarts.init(document.getElementById('chart_province_sort'));

        //chart_alarm = echarts.init(document.getElementById('chart_alarm'));
    }



    window.addEventListener("resize", function () {
        if(chart_feed){
            chart_feed.resize();
        }
        if(chart_mode){
            chart_mode.resize();
        }
        if(chart_liaota){
            chart_liaota.resize();
        }
        if(chart_online){
            chart_online.resize();
        }
        if(chart_province_sort){
            chart_province_sort.resize();
        }
        if(chart_alarm){
            chart_alarm.resize();
        }
        if(chart_map){
            chart_map.resize();
        }
    });

</script>
</html>